// pages/user/register/password/password.js
var aliyun_api = require('../../../../utils/aliyun-api-gateway.js');

Page({

  /**
   * 页面的初始数据
   */
  data: {
    phone: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    that.setData({
      phone: options.phone
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },
  formsubmit: function (e) {
    console.log(e.detail.value)
    console.log("注册")
    if (e.detail.value.password !== e.detail.value.password1) {
      wx.showToast({
        title: '密码不一致',
        icon: 'none',
        duration: 2000
      })
    } else {
      var that = this
      const params = {
        url: 'https://api.link.aliyun.com/iotx/account/registerAccount',
        apiVer: '1.0.5',
        param: {
          "request": {
            "accountMetaV2": {
              "phone": that.data.phone,
              "password": e.detail.value.password,
              "appKey": "25812429"
            }
          }
        }
      }
      aliyun_api.request(params).then(function (res) {
        //  console.log(data)
        if (res.code === 200) {
          var value = {
            id: res.data,
            password: e.detail.value.password,
          }
          const params = {
            url: 'https://api.link.aliyun.com/kvstore/put',
            apiVer: '1.1.0',
            param: {
              "key": that.data.phone,
              "value": JSON.stringify(value)
            }
          }
          aliyun_api.request(params).then(function (res) {

          })
        } else {

        }
      })
    }
    
  },
})